package org.akomantoso.core.data;

import java.io.IOException;

import org.akomantoso.core.data.attribute.Value;
import org.akomantoso.core.io.Input;
import org.akomantoso.core.io.Output;
import org.akomantoso.core.io.OutputUtil;

/**
 * The type valueType specifies a value attribute to FRBR elements.
 * 
 * <pre>
 * 	<xsd:complexType name="valueType">
 * 		<xsd:complexContent>
 * 			<xsd:extension base="metaopt">
 * 				<xsd:attributeGroup ref="value"/>
 * 			</xsd:extension>
 * 		</xsd:complexContent>
 * 	</xsd:complexType>
 * </pre>
 * 
 */
public abstract class ValueType extends MetaOpt implements Value {

	private String _value;
	
	/**
	 * @see org.akomantoso.core.data.attribute.Value#getValue()
	 */
	@Override
	public String getValue() {
		return _value;
	}

	/**
	 * @see org.akomantoso.core.data.attribute.Value#setValue(java.lang.String)
	 */
	@Override
	public void setValue(String value) {
		_value = value;
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#writeExternal(org.akomantoso.core.io.Output)
	 */
	@Override
	public <T extends Output> void writeExternal(T out) throws IOException {
		OutputUtil.writeValue(out, this);
		super.writeExternal(out);
	}

	/**
	 * @see org.akomantoso.core.data.MetaOpt#readExternal(org.akomantoso.core.io.Input)
	 */
	@Override
	public <T extends Input> void readExternal(T in) throws IOException {
		_value = in.readAttribute(Value.ATTRIBUTE);
		super.readExternal(in);
	}

}